﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;

namespace KeyCore.Domain.Model
{
    public class Osoba
    {
        public Osoba()
        {
           // DaneOsobowe = new DaneOsobowe();
        }

      //  [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public System.Guid OsobaId { get; set; }
        public string ImiePierwsze { get; set; }
        public string ImieDrugie { get; set; }
        public string Nazwisko { get; set; }
        public string NazwiskoRodowe { get; set; }

        public virtual DaneOsobowe DaneOsobowe { get; set; }

    }

    public class OsobaConfiguration : EntityTypeConfiguration<Osoba>
    {
        public OsobaConfiguration()
        {
            // PK and autogenerated guid
            HasKey(k => k.OsobaId)
                .Property(p => p.OsobaId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            // bi-directional  one-to-one with DaneOsobowe  key removed in DaneOsobowe
            HasOptional(o => o.DaneOsobowe)
                .WithRequired();; 
                //.WillCascadeOnDelete();
            Property(p => p.ImiePierwsze).IsRequired();
            Property(p => p.Nazwisko).IsRequired();
            Property(p => p.NazwiskoRodowe).IsRequired();
            Property(p => p.ImieDrugie).IsOptional();

        }
    }
}
